﻿using Coldairarrow.Business.AM;
using Coldairarrow.Entity.AM;
using Coldairarrow.Util;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Coldairarrow.Api.Controllers.AM
{
    [Route("/AM/[controller]/[action]")]
    public class AM_AssetCheckController : BaseApiController
    {
        #region DI

        public AM_AssetCheckController(IAM_AssetCheckBusiness aM_AssetCheckBus)
        {
            _aM_AssetCheckBus = aM_AssetCheckBus;
        }

        IAM_AssetCheckBusiness _aM_AssetCheckBus { get; }

        #endregion

        #region 获取

        [HttpPost]
        public async Task<PageResult<AM_AssetCheck>> GetDataList(PageInput<ConditionDTO> input)
        {
            return await _aM_AssetCheckBus.GetDataListAsync(input);
        }

        [HttpPost]
        public async Task<AM_AssetCheck> GetTheData(IdInputDTO input)
        {
            return await _aM_AssetCheckBus.GetTheDataAsync(input.id);
        }

        #endregion

        #region 提交

        [HttpPost]
        public async Task SaveData(AM_AssetCheck data)
        {
            if (data.CheckId.IsNullOrEmpty())
            {
                InitEntity(data);

                await _aM_AssetCheckBus.AddDataAsync(data);
            }
            else
            {
                await _aM_AssetCheckBus.UpdateDataAsync(data);
            }
        }

        [HttpPost]
        public async Task DeleteData(List<string> ids)
        {
            await _aM_AssetCheckBus.DeleteDataAsync(ids);
        }

        #endregion

        #region  PDA资产盘点

        /// <summary>
        /// 获取资产信息
        /// </summary>
        /// <param name="AssetQrCode">资产卡片二维码</param>
        /// <param name="AssetCheckQrCode">盘点单二维码</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<AM_AssetItemDTO> GetAssetItemData(string AssetQrCode, string AssetCheckQrCode)
        {
            return await _aM_AssetCheckBus.GetAssetItemDataAsync(AssetQrCode, AssetCheckQrCode);
        }

        /// <summary>
        /// PDA盘点保存
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task InsertAssetCheckData(AssetFirmOfferDTO data)
        {
            await _aM_AssetCheckBus.InsertAssetCheckDataAsync(data);
        }

        /// <summary>
        /// 获取实际盘点明细
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<PageResult<AM_AssetFirmOfferDTO>> GetAssetFirmOfferList(PageInput<AssetFirmOfferConditionDTO> input)
        {
            return await _aM_AssetCheckBus.GetAssetFirmOfferListAsync(input);
        }

        /// <summary>
        /// 移除实际盘点资产信息
        /// </summary>
        /// <param name="Id">实际盘点明细Id</param>
        /// <returns></returns>
        [HttpPost]
        public async Task DeleteAssetFirmOfferData(string Id)
        {
            await _aM_AssetCheckBus.DeleteAssetFirmOfferDataAsync(Id);
        }

        /// <summary>
        /// 提交资产盘点
        /// </summary>
        /// <param name="AssetCheckQrCode">盘点单二维码</param>
        /// <returns></returns>
        [HttpPost]
        public async Task SubmitAssetFirmOffer(string AssetCheckQrCode)
        {
            await _aM_AssetCheckBus.SubmitAssetFirmOfferAsync(AssetCheckQrCode);
        }

        #endregion

        #region PDA资产调拨

        /// <summary>
        /// 调拨获取资产信息
        /// </summary>
        /// <param name="AssetQrCode">资产卡片二维码</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<AM_AssetItemDTO> GetAllocationAssetItemData(string AssetQrCode)
        {
            return await _aM_AssetCheckBus.GetAllocationAssetItemDataAsync(AssetQrCode);
        }

        /// <summary>
        /// 资产调拨保存
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task SaveMotionData(AllocationAssetDTO data)
        {
            await _aM_AssetCheckBus.SaveMotionDataAsync(data);
        }

        #endregion


        #region PDA资产报废

        /// <summary>
        /// 资产报废
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task SaveAssetScrap(AssetScrapDTO data)
        {
            await _aM_AssetCheckBus.SaveAssetScrapAsync(data);
        }

        #endregion

        #region PDA资产处置

        /// <summary>
        /// 资产报废
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task SaveAssetDisposal(AssetScrapDTO data)
        {
            await _aM_AssetCheckBus.SaveAssetDisposalAsync(data);
        }

        #endregion

    }
}